﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibrarySolution.ComMethod;
using LibrarySolution.DAO.委托;
using LibrarySolution.DAO.基础;
using LibrarySolution.Model.基础;

namespace LibrarySolution.Frm
{
    public partial class FrmYhjbModify : Form
    {
        #region 属性
        Delegates delegates = new Delegates();
        YhJbDao yhjbDao = new YhJbDao();
        private static FrmYhjbModify Instance;
        public static bool IsModify = true;
        #endregion

        #region 构造器
        public FrmYhjbModify()
        {
            InitializeComponent();
        }
        #endregion

        #region 事件
        public static FrmYhjbModify GetInstance(Delegates delegates)
        {
            Instance = new FrmYhjbModify();
            if (IsModify)
                Instance.BindingData();
            else
                Instance.LblGetJbCode.Text = Instance.yhjbDao.getMaxJbCode();
            Instance.delegates = delegates;
            return Instance;
        }

        private void TstripDone_Click(object sender, EventArgs e)
        {
            JbxxDetail jbxxDetail = new JbxxDetail();
            jbxxDetail.yhjb_code = LblGetJbCode.Text;
            jbxxDetail.yhjb_name = TxtJbName.Text;
            jbxxDetail.yhjb_no = TxtJbNo.Text;
            jbxxDetail.xjqx = TxtXjqx.Text;
            jbxxDetail.jyqx = TxtJyqx.Text;
            if (IsModify)
            {
                yhjbDao.updateJbxx(jbxxDetail);
                MessageBox.Show("修改成功");
            }
            else
            {
                yhjbDao.insertJbxx(jbxxDetail);
                MessageBox.Show("添加成功");
            }
            if (Instance.delegates != null)
            {
                Instance.delegates.doWork();
            }
            this.Close();
        }
        #endregion

        #region 方法
        void BindingData()
        {
            TxtJbName.Text = GlobalVar.JbxxDetail.yhjb_name;
            TxtJbNo.Text = GlobalVar.JbxxDetail.yhjb_no;
            TxtJyqx.Text = GlobalVar.JbxxDetail.jyqx;
            TxtXjqx.Text = GlobalVar.JbxxDetail.xjqx;
            LblGetJbCode.Text = GlobalVar.JbxxDetail.yhjb_code;
        }
        #endregion
    }
}
